import {defineStore} from "pinia";

export const useStudentStore = defineStore('student', {
	// 在 userStore 的 state 中添加已选名单和可用名单
	state: () => ({
		name: '',
		original_list: ['John', 'Jane', 'Jim', 'Jack'], // 原始名单（用于重置）
		list: ['John', 'Jane', 'Jim', 'Jack'],         // 当前可用名单
		selected: [],                             // 已选名单
	}),

	// 修改 setName 方法为随机选中并记录
	actions: {
		randomSelect() {
			if (this.list.length === 0) return;
			const index = Math.floor(Math.random() * this.list.length);
			this.name = this.list[index];
		},
		selectConfirm() {
			if (!this.name || this.selected.includes(this.name)) return;
			this.selected.push(this.name);
			this.list = this.list.filter(n => n !== this.name);
			this.name = '';
		},
		resetAll() {
			this.list = [...this.original_list];
			this.selected = [];
			this.name = '';
		}
	}
})